expected primary

您所在的位置:网站首页 compilation error怎么解决 expected primary

expected primary

2024-07-09 19:39| 来源: 网络整理| 查看: 265

expected primary-expression before xx token

这个 xx 一般指运算符,比如++,—等

错误的原因是:把类型(type)当成变量来用了(variable)

如下面例子,List *head是一种类型,错误使用。

#include #include #include #define num_xuehao 6 #define num_name 10 typedef struct _item{ int s; char xue[num_xuehao]; char nam[num_name]; struct _item *next; }Item; typedef struct _list{ Item *last; Item *head; }List; void add(List *plist,char *xuehao,char *name,int score);//将新输入的项目连接在链表的后面 int main() { List *head = NULL; List *last = NULL; } void add(List *head,List *last,char *xuehao,char *name,int score) { //连接在链表后面 ,新加入的部分的每一个小点都要有初始化 Item *p=(Item*)malloc(sizeof(Item)); p->next = NULL; p->s = score; strcpy(p->xue ,xuehao); strcpy(p->nam ,name); // printf("%s %s %d\n",p->nam,p->xue,p->s); //find the last if(List->last){ while(List->last->next){ List->last=List->last->next; } List->last->next = p; } else{ List->last = p; List->head = p; } }

正确的应该是下面这样。

#include #include #include #define num_xuehao 6 #define num_name 10 typedef struct _item{ int s; char xue[num_xuehao]; char nam[num_name]; struct _item *next; }Item; typedef struct _list{ Item *last; Item *head; }List; void add(List *plist,char *xuehao,char *name,int score);//将新输入的项目连接在链表的后面 int main() { List plist; plist.head = NULL; plist.last = NULL; } void add(List *plist,char *xuehao,char *name,int score) { //连接在链表后面 ,新加入的部分的每一个小点都要有初始化 Item *p=(Item*)malloc(sizeof(Item)); p->next = NULL; p->s = score; strcpy(p->xue ,xuehao); strcpy(p->nam ,name); // printf("%s %s %d\n",p->nam,p->xue,p->s); //find the last if(plist->last){ while(plist->last->next){ plist->last=plist->last->next; } plist->last->next = p; } else{ plist->last = p; plist->head = p; } }

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3